<template>
	<view>
		<swiper class="swiper" indicator-dots="true" autoplay="true" interval="2000" duration="500">
			<swiper-item v-for="(item,index) in goodsImg">
				<image :src="item.src"></image>
			</swiper-item>			
		</swiper>
		<view class="box1">
			<view class="price">
				<text>￥{{goodsInfo.sell_price}}</text>
				<text>￥{{goodsInfo.market_price}}</text>
				<text>月销：{{goodsInfo.stock_quantity}}</text>
			</view>
			<view class="goodsName">
				{{goodsInfo.title}}
			</view>
			
		</view>
		<view class="line"></view>
		<view class="huohao">
			<view>货号：{{goodsInfo.stock_quantity}}</view>
			<view class="">库存：{{goodsInfo.goods_no}}</view>
		</view>
		<view class="line"></view>
		<view class="desc">
			<view class="title">详细介绍</view>
			<view class="content">
				<rich-text :nodes="goodsDesc.content"></rich-text>
			</view>
		
		</view>
		<view class="uni-nav">
			<uni-goods-nav fill="true" :options="options" :buttonGroup="buttonGroup" @click="onClick()" @buttonClick="buttonClick()"></uni-goods-nav>
		</view>
		
	</view>
</template>

<script>
	import uniGoodsNav from "@/components/uni-goods-nav/uni-goods-nav.vue"
	export default {
		components:{
			uniGoodsNav
		},
		data() {
			return {
				id:'',
				goodsImg:[],
				goodsInfo:{},
				goodsDesc:{},
				options: [{
							icon: 'headphones',
							text: '客服'
						}, {
							icon: 'shop',
							text: '店铺',
							info: 2,
							infoBackgroundColor:'#007aff',
							infoColor:"red"
						}, {
							icon: 'cart',
							text: '购物车',
							info: 2
						}],
					    buttonGroup: [{
					      text: '加入购物车',
					      backgroundColor: '#ff0000',
					      color: '#fff'
					    },
					    {
					      text: '立即购买',
					      backgroundColor: '#ffa200',
					      color: '#fff'
					    }
					    ]
				}
		},
		onLoad(option) {
			console.log(option.id);
			this.id = option.id
			this.getSwiters()
			this.getInfo()
			this.getDest()
			
		},
		methods: {
			onClick (e) {
				    uni.showToast({
				      title: `点击${e.content.text}`,
				      icon: 'none'
				    })
				  },
				  buttonClick (e) {
				    console.log(e)
				    this.options[2].info++
				  },
			// 轮播
			async getSwiters(){
				const res = await this.$myRequest({
					url:'/api/getthumimages/'+this.id
				})
				this.goodsImg = res.data.message
			},
			// 商品信息
			async getInfo(){
				const res = await this.$myRequest({
					url:'/api/goods/getinfo/'+this.id
				})
				this.goodsInfo = res.data.message[0]
			},
			// 商品介绍
			async getDest(){
				const res = await this.$myRequest({
					url:'/api/goods/getdesc/'+this.id
				})
				this.goodsDesc = res.data.message[0]
			},
		}
	}
</script>

<style lang="scss">
	.swiper{
		height: 700rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.box1{
		padding: 10px;
		line-height: 60rpx;
		.price{
			
			padding: 10rpx 0;
			color: red;
			font-size: 36rpx;
			text:nth-child(2){
				color: #999999;
				font-size: 25rpx;
				text-decoration: line-through;
			}
			text:nth-child(3){
				font-size: 32rpx;
				color: #262626;
				margin-right: 10px;
				float: right;
			}
		}
		.goodsName{
			font-size: 32rpx;
			line-height: 60rpx;
		}
		
	}
	.line{
		width: 750rpx;
		height: 10rpx;
		background: #C0C0C0;
	}
	.huohao{
		view{
			line-height: 60rpx;
			font-style: 32rpx;
			padding: 5px 10px;
		}
	}
	.desc{
		
		.title{
			padding-left: 10px;
			
			line-height: 80rpx;
			font-style: 30rpx;
			border-bottom: 1px solid #999999;
			
		}
		.content{
			padding: 10px;
			line-height: 60rpx;
			image{
				
			}
		}
	}
	.uni-nav{
		position: fixed;
		bottom: 0;
		width: 100%;
	}
</style>
